<template>
  <confirm-dialog
  :title="$t('user.CloseSMSTitle')"
    :visible="visible"
    :loading="loading"
    @handleClose="handleClose"
    width="25%"
  >
  <template slot="content">
    <span class="tips">{{$t('user.CloseSMSTips')}}</span>
  </template>
  <template slot="footer">
    <el-button @click="handleClose">{{$t('common.cancel')}}</el-button>
    <el-button :loading="loading"  type="primary" @click="submit">{{$t('common.confirm')}}</el-button>
  </template>
  </confirm-dialog>
</template>
<script lang="ts">
import Vue from 'vue'
import ConfirmDialog from '../../../components/Dialog/confirmDialog.vue';
export default Vue.extend({
  props: {
    submitMethod: {
      type: Function,
      default() {
        return () => Promise.resolve();
      }
    }
  },
  components: {
    ConfirmDialog
  },
  data() {
    return {
      title: '',
      visible: false,
      loading: false,
      content: '',
      item: '',
      userData: '',
      isBatch: false
    }
  },
  methods: {
    init(item: any, isBatch: any) {
      (this as any).visible = true;
      (this as any).userData = JSON.parse(JSON.stringify(item));
      this.isBatch = isBatch;
    },
    submit() {
      (this as any).loading = true;
      let lists = [];
      if(this.isBatch) {
        for(let i in (this as any).userData){
          lists.push((this as any).userData[i].id);
        }
      }else {
        lists.push((this as any).userData.id);
      }
      const data: any = {
        attr: "enable_sms_certification",
        attr_value: false,
        user_list: lists
      };
      this.$tunnyApi.apiSetUserSms(data).then((res: any) => {
        if(res.code == 2000) {
          (this as any).$message.success(this.$t('user.closeSmsSuccess'));
          this.$emit("success");
          (this as any).handleClose();
        } else {
          (this as any).$message.warning(this.$t('user.closeSmsFail'));
          (this as any).handleClose();
        }
      })
    },
    handleClose() {
      (this as any).visible = false;
      (this as any).loading = false;
    } 
  }
})
</script>
<style scoped>
.tips {
  font-size: 12px;
  color: gray;
}
</style>
